//连接数据库

const mongoose = require('mongoose');
const { DBHOST, DBPOST, DBNAME } = require('../config/config');

const dburl = `mongodb://${DBHOST}:${DBPOST}/${DBNAME}`;


module.exports = function () {

    return new Promise((resolve, reject) => {
        mongoose.connect(dburl);

        mongoose.connection.once('open', () => {
            console.log('连接成功');

            resolve();
        });

        mongoose.connection.on('error', (error) => {
            console.log('连接失败...');

            reject(error);
        });
    })
}


